
<template>
  <div class="login">
    <div class="mylogin" align="center">
      <h2>信息审核后台</h2>
      <el-form
          :model="loginForm"
          :rules="loginRules"
          ref="loginForm"
          label-width="0px"
      >
        <el-form-item label="" prop="idNumber">
          <el-row>
            <el-col :span="2">
              <span class="el-icon-lock" style="color: black;"></span>
            </el-col>
            <el-col :span="22">
              <el-input
                  class="inps"
                  placeholder="密码"
                  v-model="loginForm.idNumber"
              ></el-input>
            </el-col>
          </el-row>
        </el-form-item>
        <div class="yzmBtn">
          <el-button type="primary"  @click="getCode"
          >人机验证
          </el-button>
          <div class="icon" v-show="yzm">
            <i class="el-icon-check"></i>
          </div>
        </div>
        <div>
          <!-- 登录时的滑动图片验证码,覆盖整个页面 -->
          <div class="mask" v-show="isShowSlide" @click.self="isShowSlide = false">
            <div class="slideContainer">
              <SlideVerify ref="slideblock" :successFun="successVerify"></SlideVerify>
            </div>
          </div>
        </div>
        <el-form-item style="margin-top: 55px">
          <el-button type="primary" round class="submitBtn" @click="submitForm"
          >登录
          </el-button>
        </el-form-item>

      </el-form>
    </div>

  </div>
</template>


<script>
import SlideVerify from '@/components/slideverify'
import {UserMsgGetByid, UserMsgLogin} from "@/request/utils/user";
import {sm4} from "sm-crypto";

export default {
  name: "Login",
  components:{
    SlideVerify
  },
  data: function () {
    return {
      isShowSlide: false,
      yzm: false,
      loginForm: {
        id: "1",
        name: "admin",
        idNumber: "",
      },
      loginRules: {
        name: [{ required: true, message: "请输入账号", trigger: "blur" }],
        idNumber: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      dialogVisible: false,
      admins: ["0000"]
    };
  },

  methods: {
    //验证码验证成功
    successVerify(){
      this.yzm = true;
      this.isShowSlide = false;

    },
    getCode(){
      this.isShowSlide = true;
      // 触发方法，每次打开遮罩层都刷新组件
      this.$bus.$emit('resetSlideVerify')
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
    submitForm() {
      const idCard = this.loginForm.idNumber;
      if (!this.yzm) {
        return this.$message({
          type: "error",
          message: "人机验证未通过！",
        });
      }
      if (!idCard) {
        return this.$message({
          type: "error",
          message: "密码不能为空！",
        });
      }
      const loading = this.$loading({
        lock: true,
        text: '登录中~',
        spinner: 'el-icon-loading',
        background: 'rgba(255, 255, 255, 0.8)'
      });
      setTimeout(() => {
        const key = '0123456789abcdeffedcba9876543210' // 16 字节的十六进制密钥
        this.loginForm.name =sm4.encrypt(this.loginForm.name,key)
        this.loginForm.idNumber =sm4.encrypt(this.loginForm.idNumber,key)
        UserMsgLogin(this.loginForm).then(res=>{
          this.loginForm = {
            id: "1",
            name: "admin",
            idNumber: ""
          }
          if(res.code === 0){
            var expiration = new Date().getTime() + (1 * 60 * 60 * 1000);
            localStorage.setItem('user', JSON.stringify({ value: idCard, expiration: expiration }));
            localStorage.setItem('token', res.token);
            this.$router.push('/back');
          }else {
            this.$message({
              type: "error",
              message: res.msg,
            });
          }
        })
        loading.close();
      }, 1000);

    },

  },
};
</script>


<style scoped lang="less">

.login {
  width: 100vw;
  padding: 0;
  margin: 0;
  height: 100vh;
  font-size: 16px;
  background-position: left top;
  background-image: url("../assets/bg4.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  z-index: 1000;

  color: #fff;
  font-family: "Source Sans Pro";
  position: relative;

}

.mylogin {
  width: 340px;
  height: 300px;
  position: absolute;
  background: white;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  padding: 50px 40px 40px 40px;
  box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7);
  opacity: 1;

  h2{
    color: black;
    margin-bottom: 50px;
  }

}

.inps input {
  border: none;
  color: #fff;
  background-color: transparent;
  font-size: 12px;
}

.submitBtn {
  background-color: transparent;
  color: #39f;
  width: 200px;
}

.dialogUser{
  .dialogBox{
    display: flex;
    flex-direction:column;
    justify-content:center;
    text-align: center;
    width: 100%;
    h2{
      margin-top: 50px;
      color: red;
      font-size: 30px;
    }
    span{
      margin: 50px 0;
      font-size: 20px;
      display: inline-block;
    }

  }
  button{
    margin-left: 50px;
  }
}

.mask {
  position: fixed;
  left: 0%;
  top: 0%;
  width: 100%;
  height: 100%;
  z-index: 100;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.5);
}
.mask .slideContainer {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  width: 380px;
  height: 250px;
  background-color: rgb(255, 255, 255);
}

.yzmBtn{
  display: flex;
  justify-content: center;
  align-items: center;
  .icon{
    margin-left: 50px;
    color: green;
    font-size: 30px;
  }
}

</style>
